package com.tapjoy;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TapjoyVideo
{
  public static final String TAPJOY_VIDEO = "TapjoyVideo";
  private static TapjoyVideo tapjoyVideo = null;
  private static TapjoyVideoNotifier tapjoyVideoNotifier;
  private static Bitmap watermarkImage;
  private static final String watermarkURL = "https://s3.amazonaws.com/tapjoy/videos/assets/watermark.png";
  private boolean cache3g = false;
  private boolean cacheAuto = false;
  private boolean cacheWifi = false;
  private Hashtable<String, TapjoyVideoObject> cachedVideos;
  Context context;
  private String imageCacheDir = null;
  private boolean initialized = false;
  private Hashtable<String, TapjoyVideoObject> uncachedVideos;
  private String videoCacheDir = null;
  private int videoCacheLimit = 5;
  private Vector<String> videoQueue;
  private TapjoyVideoObject videoToPlay;

  public TapjoyVideo(Context paramContext)
  {
    this.context = paramContext;
    tapjoyVideo = this;
    this.videoCacheDir = (Environment.getExternalStorageDirectory().toString() + "/tjcache/data/");
    this.imageCacheDir = (Environment.getExternalStorageDirectory().toString() + "/tjcache/tmp/");
    TapjoyUtil.deleteFileOrDirectory(new File(Environment.getExternalStorageDirectory().toString() + "/tapjoy/"));
    TapjoyUtil.deleteFileOrDirectory(new File(this.imageCacheDir));
    this.videoQueue = new Vector();
    this.uncachedVideos = new Hashtable();
    this.cachedVideos = new Hashtable();
    if ((TapjoyConnectCore.getFlagValue("video_cache_count") != null) && (TapjoyConnectCore.getFlagValue("video_cache_count").length() > 0));
    try
    {
      TapjoyLog.i("TapjoyVideo", "Setting video cache count to: " + TapjoyConnectCore.getFlagValue("video_cache_count"));
      setVideoCacheCount(Integer.parseInt(TapjoyConnectCore.getFlagValue("video_cache_count")));
      init();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        TapjoyLog.e("TapjoyVideo", "Error, invalid value for video_cache_count: " + TapjoyConnectCore.getFlagValue("video_cache_count"));
    }
  }

  // ERROR //
  private void cacheVideoFromURL(String paramString)
  {
    // Byte code:
    //   0: ldc 8
    //   2: new 65	java/lang/StringBuilder
    //   5: dup
    //   6: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   9: ldc 197
    //   11: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   14: aload_1
    //   15: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   18: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   21: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   24: invokestatic 203	java/lang/System:currentTimeMillis	()J
    //   27: lstore_2
    //   28: aconst_null
    //   29: astore 4
    //   31: aconst_null
    //   32: astore 5
    //   34: aconst_null
    //   35: astore 6
    //   37: new 205	java/net/URL
    //   40: dup
    //   41: aload_1
    //   42: invokespecial 206	java/net/URL:<init>	(Ljava/lang/String;)V
    //   45: invokevirtual 210	java/net/URL:openConnection	()Ljava/net/URLConnection;
    //   48: astore 17
    //   50: aload 17
    //   52: sipush 15000
    //   55: invokevirtual 215	java/net/URLConnection:setConnectTimeout	(I)V
    //   58: aload 17
    //   60: sipush 30000
    //   63: invokevirtual 218	java/net/URLConnection:setReadTimeout	(I)V
    //   66: aload 17
    //   68: invokevirtual 221	java/net/URLConnection:connect	()V
    //   71: new 223	java/io/BufferedInputStream
    //   74: dup
    //   75: aload 17
    //   77: invokevirtual 227	java/net/URLConnection:getInputStream	()Ljava/io/InputStream;
    //   80: invokespecial 230	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   83: astore 18
    //   85: new 74	java/io/File
    //   88: dup
    //   89: aload_0
    //   90: getfield 49	com/tapjoy/TapjoyVideo:videoCacheDir	Ljava/lang/String;
    //   93: invokespecial 92	java/io/File:<init>	(Ljava/lang/String;)V
    //   96: astore 19
    //   98: aload_1
    //   99: iconst_0
    //   100: iconst_1
    //   101: aload_1
    //   102: ldc 232
    //   104: invokevirtual 235	java/lang/String:lastIndexOf	(Ljava/lang/String;)I
    //   107: iadd
    //   108: invokevirtual 239	java/lang/String:substring	(II)Ljava/lang/String;
    //   111: astore 20
    //   113: aload_1
    //   114: iconst_1
    //   115: aload_1
    //   116: ldc 232
    //   118: invokevirtual 235	java/lang/String:lastIndexOf	(Ljava/lang/String;)I
    //   121: iadd
    //   122: invokevirtual 242	java/lang/String:substring	(I)Ljava/lang/String;
    //   125: astore 21
    //   127: aload 21
    //   129: iconst_0
    //   130: aload 21
    //   132: bipush 46
    //   134: invokevirtual 246	java/lang/String:indexOf	(I)I
    //   137: invokevirtual 239	java/lang/String:substring	(II)Ljava/lang/String;
    //   140: astore 22
    //   142: ldc 8
    //   144: new 65	java/lang/StringBuilder
    //   147: dup
    //   148: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   151: ldc 248
    //   153: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   156: aload 19
    //   158: invokevirtual 251	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   161: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   164: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   167: ldc 8
    //   169: new 65	java/lang/StringBuilder
    //   172: dup
    //   173: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   176: ldc 253
    //   178: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   181: aload 20
    //   183: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   186: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   189: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   192: ldc 8
    //   194: new 65	java/lang/StringBuilder
    //   197: dup
    //   198: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   201: ldc 255
    //   203: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   206: aload 22
    //   208: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   211: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   214: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   217: aload 19
    //   219: invokevirtual 258	java/io/File:mkdirs	()Z
    //   222: ifeq +32 -> 254
    //   225: ldc 8
    //   227: new 65	java/lang/StringBuilder
    //   230: dup
    //   231: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   234: ldc_w 260
    //   237: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   240: aload 19
    //   242: invokevirtual 263	java/io/File:getPath	()Ljava/lang/String;
    //   245: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   248: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   251: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   254: new 74	java/io/File
    //   257: dup
    //   258: aload_0
    //   259: getfield 49	com/tapjoy/TapjoyVideo:videoCacheDir	Ljava/lang/String;
    //   262: aload 22
    //   264: invokespecial 265	java/io/File:<init>	(Ljava/lang/String;Ljava/lang/String;)V
    //   267: astore 23
    //   269: new 267	java/io/FileOutputStream
    //   272: dup
    //   273: aload 23
    //   275: invokespecial 269	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   278: astore 24
    //   280: ldc 8
    //   282: new 65	java/lang/StringBuilder
    //   285: dup
    //   286: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   289: ldc_w 271
    //   292: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   295: aload 23
    //   297: invokevirtual 78	java/io/File:toString	()Ljava/lang/String;
    //   300: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   303: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   306: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   309: sipush 1024
    //   312: newarray byte
    //   314: astore 25
    //   316: aload 18
    //   318: aload 25
    //   320: invokevirtual 275	java/io/BufferedInputStream:read	([B)I
    //   323: istore 26
    //   325: iload 26
    //   327: iconst_m1
    //   328: if_icmpeq +206 -> 534
    //   331: aload 24
    //   333: aload 25
    //   335: iconst_0
    //   336: iload 26
    //   338: invokevirtual 281	java/io/OutputStream:write	([BII)V
    //   341: goto -25 -> 316
    //   344: astore 7
    //   346: aload 23
    //   348: astore 6
    //   350: aload 24
    //   352: astore 5
    //   354: aload 18
    //   356: astore 4
    //   358: ldc 8
    //   360: new 65	java/lang/StringBuilder
    //   363: dup
    //   364: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   367: ldc_w 283
    //   370: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   373: aload 7
    //   375: invokevirtual 284	java/net/SocketTimeoutException:toString	()Ljava/lang/String;
    //   378: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   381: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   384: invokestatic 150	com/tapjoy/TapjoyLog:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   387: iconst_1
    //   388: istore 8
    //   390: iconst_1
    //   391: istore 9
    //   393: iload 8
    //   395: iconst_1
    //   396: if_icmpne +21 -> 417
    //   399: ldc 8
    //   401: ldc_w 286
    //   404: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   407: aload 4
    //   409: invokevirtual 289	java/io/BufferedInputStream:close	()V
    //   412: aload 5
    //   414: invokevirtual 290	java/io/OutputStream:close	()V
    //   417: iload 8
    //   419: ifne +268 -> 687
    //   422: iload 9
    //   424: ifne +263 -> 687
    //   427: aload_0
    //   428: getfield 103	com/tapjoy/TapjoyVideo:videoQueue	Ljava/util/Vector;
    //   431: iconst_0
    //   432: invokevirtual 294	java/util/Vector:elementAt	(I)Ljava/lang/Object;
    //   435: checkcast 120	java/lang/String
    //   438: astore 11
    //   440: aload_0
    //   441: getfield 108	com/tapjoy/TapjoyVideo:uncachedVideos	Ljava/util/Hashtable;
    //   444: aload 11
    //   446: invokevirtual 298	java/util/Hashtable:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   449: checkcast 300	com/tapjoy/TapjoyVideoObject
    //   452: astore 12
    //   454: aload 12
    //   456: aload 6
    //   458: invokevirtual 303	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   461: putfield 306	com/tapjoy/TapjoyVideoObject:dataLocation	Ljava/lang/String;
    //   464: aload_0
    //   465: getfield 110	com/tapjoy/TapjoyVideo:cachedVideos	Ljava/util/Hashtable;
    //   468: aload 11
    //   470: aload 12
    //   472: invokevirtual 310	java/util/Hashtable:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   475: pop
    //   476: aload_0
    //   477: getfield 108	com/tapjoy/TapjoyVideo:uncachedVideos	Ljava/util/Hashtable;
    //   480: aload 11
    //   482: invokevirtual 313	java/util/Hashtable:remove	(Ljava/lang/Object;)Ljava/lang/Object;
    //   485: pop
    //   486: aload_0
    //   487: getfield 103	com/tapjoy/TapjoyVideo:videoQueue	Ljava/util/Vector;
    //   490: iconst_0
    //   491: invokevirtual 316	java/util/Vector:removeElementAt	(I)V
    //   494: aload_0
    //   495: invokespecial 184	com/tapjoy/TapjoyVideo:setVideoIDs	()V
    //   498: ldc 8
    //   500: new 65	java/lang/StringBuilder
    //   503: dup
    //   504: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   507: ldc_w 318
    //   510: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   513: invokestatic 203	java/lang/System:currentTimeMillis	()J
    //   516: lload_2
    //   517: lsub
    //   518: invokevirtual 321	java/lang/StringBuilder:append	(J)Ljava/lang/StringBuilder;
    //   521: ldc_w 323
    //   524: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   527: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   530: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   533: return
    //   534: aload 24
    //   536: invokevirtual 290	java/io/OutputStream:close	()V
    //   539: aload 18
    //   541: invokevirtual 289	java/io/BufferedInputStream:close	()V
    //   544: ldc 8
    //   546: new 65	java/lang/StringBuilder
    //   549: dup
    //   550: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   553: ldc_w 325
    //   556: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   559: aload 23
    //   561: invokevirtual 327	java/io/File:length	()J
    //   564: invokevirtual 321	java/lang/StringBuilder:append	(J)Ljava/lang/StringBuilder;
    //   567: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   570: invokestatic 132	com/tapjoy/TapjoyLog:i	(Ljava/lang/String;Ljava/lang/String;)V
    //   573: aload 23
    //   575: invokevirtual 327	java/io/File:length	()J
    //   578: lstore 27
    //   580: lload 27
    //   582: lconst_0
    //   583: lcmp
    //   584: istore 29
    //   586: iconst_0
    //   587: istore 8
    //   589: iload 29
    //   591: ifne +6 -> 597
    //   594: iconst_1
    //   595: istore 8
    //   597: aload 23
    //   599: astore 6
    //   601: aload 24
    //   603: astore 5
    //   605: aload 18
    //   607: astore 4
    //   609: iconst_0
    //   610: istore 9
    //   612: goto -219 -> 393
    //   615: astore 16
    //   617: ldc 8
    //   619: new 65	java/lang/StringBuilder
    //   622: dup
    //   623: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   626: ldc_w 329
    //   629: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   632: aload 16
    //   634: invokevirtual 330	java/lang/Exception:toString	()Ljava/lang/String;
    //   637: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   640: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   643: invokestatic 150	com/tapjoy/TapjoyLog:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   646: iconst_1
    //   647: istore 9
    //   649: iconst_0
    //   650: istore 8
    //   652: goto -259 -> 393
    //   655: astore 10
    //   657: ldc 8
    //   659: new 65	java/lang/StringBuilder
    //   662: dup
    //   663: invokespecial 66	java/lang/StringBuilder:<init>	()V
    //   666: ldc_w 332
    //   669: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   672: aload 10
    //   674: invokevirtual 330	java/lang/Exception:toString	()Ljava/lang/String;
    //   677: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   680: invokevirtual 85	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   683: invokestatic 150	com/tapjoy/TapjoyLog:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   686: return
    //   687: iconst_2
    //   688: invokestatic 335	com/tapjoy/TapjoyVideo:videoNotifierError	(I)V
    //   691: return
    //   692: astore 15
    //   694: goto -277 -> 417
    //   697: astore 16
    //   699: aload 18
    //   701: astore 4
    //   703: aconst_null
    //   704: astore 5
    //   706: aconst_null
    //   707: astore 6
    //   709: goto -92 -> 617
    //   712: astore 16
    //   714: aload 23
    //   716: astore 6
    //   718: aload 18
    //   720: astore 4
    //   722: aconst_null
    //   723: astore 5
    //   725: goto -108 -> 617
    //   728: astore 16
    //   730: aload 23
    //   732: astore 6
    //   734: aload 24
    //   736: astore 5
    //   738: aload 18
    //   740: astore 4
    //   742: goto -125 -> 617
    //   745: astore 7
    //   747: aconst_null
    //   748: astore 4
    //   750: aconst_null
    //   751: astore 5
    //   753: aconst_null
    //   754: astore 6
    //   756: goto -398 -> 358
    //   759: astore 7
    //   761: aload 18
    //   763: astore 4
    //   765: aconst_null
    //   766: astore 5
    //   768: aconst_null
    //   769: astore 6
    //   771: goto -413 -> 358
    //   774: astore 7
    //   776: aload 23
    //   778: astore 6
    //   780: aload 18
    //   782: astore 4
    //   784: aconst_null
    //   785: astore 5
    //   787: goto -429 -> 358
    //
    // Exception table:
    //   from	to	target	type
    //   280	316	344	java/net/SocketTimeoutException
    //   316	325	344	java/net/SocketTimeoutException
    //   331	341	344	java/net/SocketTimeoutException
    //   534	580	344	java/net/SocketTimeoutException
    //   37	85	615	java/lang/Exception
    //   427	533	655	java/lang/Exception
    //   407	417	692	java/lang/Exception
    //   85	254	697	java/lang/Exception
    //   254	269	697	java/lang/Exception
    //   269	280	712	java/lang/Exception
    //   280	316	728	java/lang/Exception
    //   316	325	728	java/lang/Exception
    //   331	341	728	java/lang/Exception
    //   534	580	728	java/lang/Exception
    //   37	85	745	java/net/SocketTimeoutException
    //   85	254	759	java/net/SocketTimeoutException
    //   254	269	759	java/net/SocketTimeoutException
    //   269	280	774	java/net/SocketTimeoutException
  }

  public static TapjoyVideo getInstance()
  {
    return tapjoyVideo;
  }

  public static Bitmap getWatermarkImage()
  {
    return watermarkImage;
  }

  private boolean handleGetVideosResponse(String paramString)
  {
    DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
    TapjoyLog.i("TapjoyVideo", "========================================");
    while (true)
    {
      int i;
      TapjoyVideoObject localTapjoyVideoObject;
      int j;
      try
      {
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramString.getBytes("UTF-8"));
        Document localDocument = localDocumentBuilderFactory.newDocumentBuilder().parse(localByteArrayInputStream);
        localDocument.getDocumentElement().normalize();
        NodeList localNodeList1 = localDocument.getElementsByTagName("TapjoyVideos");
        NodeList localNodeList2 = localNodeList1.item(0).getChildNodes();
        NamedNodeMap localNamedNodeMap = localNodeList1.item(0).getAttributes();
        if ((localNamedNodeMap.getNamedItem("cache_auto") != null) && (localNamedNodeMap.getNamedItem("cache_auto").getNodeValue() != null))
          this.cacheAuto = Boolean.valueOf(localNamedNodeMap.getNamedItem("cache_auto").getNodeValue()).booleanValue();
        if ((localNamedNodeMap.getNamedItem("cache_wifi") != null) && (localNamedNodeMap.getNamedItem("cache_wifi").getNodeValue() != null))
          this.cacheWifi = Boolean.valueOf(localNamedNodeMap.getNamedItem("cache_wifi").getNodeValue()).booleanValue();
        if ((localNamedNodeMap.getNamedItem("cache_mobile") != null) && (localNamedNodeMap.getNamedItem("cache_mobile").getNodeValue() != null))
          this.cache3g = Boolean.valueOf(localNamedNodeMap.getNamedItem("cache_mobile").getNodeValue()).booleanValue();
        TapjoyLog.i("TapjoyVideo", "cacheAuto: " + this.cacheAuto);
        TapjoyLog.i("TapjoyVideo", "cacheWifi: " + this.cacheWifi);
        TapjoyLog.i("TapjoyVideo", "cache3g: " + this.cache3g);
        TapjoyLog.i("TapjoyVideo", "nodelistParent length: " + localNodeList1.getLength());
        TapjoyLog.i("TapjoyVideo", "nodelist length: " + localNodeList2.getLength());
        i = 0;
        if (i >= localNodeList2.getLength())
          break label1156;
        Node localNode = localNodeList2.item(i);
        localTapjoyVideoObject = new TapjoyVideoObject();
        if ((localNode == null) || (localNode.getNodeType() != 1))
          break label1150;
        Element localElement = (Element)localNode;
        String str1 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("ClickURL"));
        if ((str1 != null) && (!str1.equals("")))
          localTapjoyVideoObject.clickURL = str1;
        String str2 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("OfferID"));
        if ((str2 != null) && (!str2.equals("")))
          localTapjoyVideoObject.offerID = str2;
        String str3 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("Name"));
        if ((str3 != null) && (!str3.equals("")))
          localTapjoyVideoObject.videoAdName = str3;
        String str4 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("Amount"));
        if ((str4 != null) && (!str4.equals("")))
          localTapjoyVideoObject.currencyAmount = str4;
        String str5 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("CurrencyName"));
        if ((str5 != null) && (!str5.equals("")))
          localTapjoyVideoObject.currencyName = str5;
        String str6 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("VideoURL"));
        if ((str6 != null) && (!str6.equals("")))
          localTapjoyVideoObject.videoURL = str6;
        String str7 = TapjoyUtil.getNodeTrimValue(localElement.getElementsByTagName("IconURL"));
        if ((str7 != null) && (!str7.equals("")))
          localTapjoyVideoObject.iconURL = str7;
        TapjoyLog.i("TapjoyVideo", "-----");
        TapjoyLog.i("TapjoyVideo", "videoObject.offerID: " + localTapjoyVideoObject.offerID);
        TapjoyLog.i("TapjoyVideo", "videoObject.videoAdName: " + localTapjoyVideoObject.videoAdName);
        TapjoyLog.i("TapjoyVideo", "videoObject.videoURL: " + localTapjoyVideoObject.videoURL);
        NodeList localNodeList3 = localElement.getElementsByTagName("Buttons").item(0).getChildNodes();
        j = 0;
        if (j < localNodeList3.getLength())
        {
          NodeList localNodeList4 = localNodeList3.item(j).getChildNodes();
          if (localNodeList4.getLength() != 0)
            break label1172;
          break label1166;
          if (k < localNodeList4.getLength())
          {
            if ((Element)localNodeList4.item(k) == null)
              break label1188;
            String str10 = ((Element)localNodeList4.item(k)).getTagName();
            if ((str10.equals("Name")) && (localNodeList4.item(k).getFirstChild() != null))
            {
              str8 = localNodeList4.item(k).getFirstChild().getNodeValue();
              break label1188;
            }
            if ((!str10.equals("URL")) || (localNodeList4.item(k).getFirstChild() == null))
              break label1188;
            str9 = localNodeList4.item(k).getFirstChild().getNodeValue();
            break label1188;
          }
          TapjoyLog.i("TapjoyVideo", "name: " + str8 + ", url: " + str9);
          localTapjoyVideoObject.addButton(str8, str9);
        }
      }
      catch (Exception localException)
      {
        TapjoyLog.e("TapjoyVideo", "Error parsing XML: " + localException.toString());
        return false;
      }
      this.videoQueue.addElement(localTapjoyVideoObject.offerID);
      this.uncachedVideos.put(localTapjoyVideoObject.offerID, localTapjoyVideoObject);
      label1150: i++;
      continue;
      label1156: TapjoyLog.i("TapjoyVideo", "========================================");
      return true;
      label1166: j++;
      continue;
      label1172: String str8 = "";
      String str9 = "";
      int k = 0;
      continue;
      label1188: k++;
    }
  }

  private void printCachedVideos()
  {
    TapjoyLog.i("TapjoyVideo", "cachedVideos size: " + this.cachedVideos.size());
    Iterator localIterator = this.cachedVideos.entrySet().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      TapjoyLog.i("TapjoyVideo", "key: " + (String)localEntry.getKey() + ", name: " + ((TapjoyVideoObject)localEntry.getValue()).videoAdName);
    }
  }

  private void setVideoIDs()
  {
    String str1 = "";
    if ((this.cachedVideos != null) && (this.cachedVideos.size() > 0))
    {
      Enumeration localEnumeration = this.cachedVideos.keys();
      while (localEnumeration.hasMoreElements())
      {
        String str2 = (String)localEnumeration.nextElement();
        str1 = str1 + str2;
        if (localEnumeration.hasMoreElements())
          str1 = str1 + ",";
      }
      TapjoyLog.i("TapjoyVideo", "cachedVideos size: " + this.cachedVideos.size());
    }
    TapjoyLog.i("TapjoyVideo", "videoIDs: [" + str1 + "]");
    TapjoyConnectCore.setVideoIDs(str1);
  }

  private boolean validateCachedVideos()
  {
    int i = 1;
    File[] arrayOfFile = new File(this.videoCacheDir).listFiles();
    if (this.uncachedVideos == null)
    {
      TapjoyLog.e("TapjoyVideo", "Error: uncachedVideos is null");
      i = 0;
    }
    if (this.cachedVideos == null)
    {
      TapjoyLog.e("TapjoyVideo", "Error: cachedVideos is null");
      i = 0;
    }
    if (this.videoQueue == null)
    {
      TapjoyLog.e("TapjoyVideo", "Error: videoQueue is null");
      i = 0;
    }
    boolean bool = false;
    if (i != 0)
    {
      bool = false;
      if (arrayOfFile != null)
      {
        int j = 0;
        if (j < arrayOfFile.length)
        {
          String str1 = arrayOfFile[j].getName();
          TapjoyLog.i("TapjoyVideo", "-----");
          TapjoyLog.i("TapjoyVideo", "Examining cached file[" + j + "]: " + arrayOfFile[j].getAbsolutePath() + " --- " + arrayOfFile[j].getName());
          TapjoyVideoObject localTapjoyVideoObject;
          if (this.uncachedVideos.containsKey(str1))
          {
            TapjoyLog.i("TapjoyVideo", "Local file found");
            localTapjoyVideoObject = (TapjoyVideoObject)this.uncachedVideos.get(str1);
            if (localTapjoyVideoObject != null);
          }
          while (true)
          {
            j++;
            break;
            String str2 = new TapjoyURLConnection().getContentLength(localTapjoyVideoObject.videoURL);
            TapjoyLog.i("TapjoyVideo", "local file size: " + arrayOfFile[j].length() + " vs. target: " + str2);
            if ((str2 != null) && (Integer.parseInt(str2) == arrayOfFile[j].length()))
            {
              localTapjoyVideoObject.dataLocation = arrayOfFile[j].getAbsolutePath();
              this.cachedVideos.put(str1, localTapjoyVideoObject);
              this.uncachedVideos.remove(str1);
              this.videoQueue.remove(str1);
              TapjoyLog.i("TapjoyVideo", "VIDEO PREVIOUSLY CACHED -- " + str1 + ", location: " + localTapjoyVideoObject.dataLocation);
            }
            else
            {
              TapjoyLog.i("TapjoyVideo", "file size mismatch --- deleting video: " + arrayOfFile[j].getAbsolutePath());
              TapjoyUtil.deleteFileOrDirectory(arrayOfFile[j]);
              continue;
              TapjoyLog.i("TapjoyVideo", "VIDEO EXPIRED? removing video from cache: " + str1 + " --- " + arrayOfFile[j].getAbsolutePath());
              TapjoyUtil.deleteFileOrDirectory(arrayOfFile[j]);
            }
          }
        }
        bool = true;
      }
    }
    return bool;
  }

  public static void videoNotifierComplete()
  {
    if (tapjoyVideoNotifier != null)
      tapjoyVideoNotifier.videoComplete();
  }

  public static void videoNotifierError(int paramInt)
  {
    if (tapjoyVideoNotifier != null)
      tapjoyVideoNotifier.videoError(paramInt);
  }

  public static void videoNotifierStart()
  {
    if (tapjoyVideoNotifier != null)
      tapjoyVideoNotifier.videoStart();
  }

  public void cacheVideos()
  {
    new Thread(new Runnable()
    {
      public void run()
      {
        TapjoyLog.i("TapjoyVideo", "--- cacheAllVideos called ---");
        int i = 0;
        while (!TapjoyVideo.this.initialized)
          try
          {
            Thread.sleep(500L);
            i = (int)(500L + i);
            if (i > 10000L)
            {
              TapjoyLog.e("TapjoyVideo", "Error during cacheVideos.  Timeout while waiting for initVideos to finish.");
              return;
            }
          }
          catch (Exception localException)
          {
            TapjoyLog.e("TapjoyVideo", "Exception in cacheAllVideos: " + localException.toString());
          }
        TapjoyLog.i("TapjoyVideo", "cacheVideos connection_type: " + TapjoyConnectCore.getConnectionType());
        TapjoyLog.i("TapjoyVideo", "cache3g: " + TapjoyVideo.this.cache3g);
        TapjoyLog.i("TapjoyVideo", "cacheWifi: " + TapjoyVideo.this.cacheWifi);
        if (((TapjoyVideo.this.cache3g) && (TapjoyConnectCore.getConnectionType().equals("mobile"))) || ((TapjoyVideo.this.cacheWifi) && (TapjoyConnectCore.getConnectionType().equals("wifi"))))
          if (!"mounted".equals(Environment.getExternalStorageState()))
          {
            TapjoyLog.i("TapjoyVideo", "Media storage unavailable.  Aborting caching videos.");
            TapjoyVideo.videoNotifierError(1);
            return;
          }
        while ((TapjoyVideo.this.cachedVideos.size() < TapjoyVideo.this.videoCacheLimit) && (TapjoyVideo.this.videoQueue.size() > 0))
        {
          String str = ((TapjoyVideoObject)TapjoyVideo.this.uncachedVideos.get(TapjoyVideo.this.videoQueue.elementAt(0))).videoURL;
          TapjoyVideo.this.cacheVideoFromURL(str);
          continue;
          TapjoyLog.i("TapjoyVideo", " * Skipping caching videos because of video flags and connection_type...");
        }
        TapjoyVideo.this.printCachedVideos();
      }
    }).start();
  }

  public void enableVideoCache(boolean paramBoolean)
  {
  }

  public TapjoyVideoObject getCurrentVideoData()
  {
    return this.videoToPlay;
  }

  public void init()
  {
    TapjoyLog.i("TapjoyVideo", "initVideoAd");
    if ((TapjoyConnectCore.getFlagValue("disable_videos") != null) && (TapjoyConnectCore.getFlagValue("disable_videos").equals("true")))
    {
      TapjoyLog.i("TapjoyVideo", "disable_videos: " + TapjoyConnectCore.getFlagValue("disable_videos") + ". Aborting video initializing... ");
      TapjoyConnectCore.setVideoEnabled(false);
      return;
    }
    setVideoIDs();
    new Thread(new Runnable()
    {
      public void run()
      {
        String str1 = TapjoyConnectCore.getURLParams();
        String str2 = str1 + "&publisher_user_id=" + TapjoyConnectCore.getUserID();
        String str3 = new TapjoyURLConnection().connectToURL("https://ws.tapjoyads.com/videos?", str2);
        boolean bool = false;
        if (str3 != null)
        {
          int i = str3.length();
          bool = false;
          if (i > 0)
            bool = TapjoyVideo.this.handleGetVideosResponse(str3);
        }
        if (bool)
        {
          TapjoyVideo.this.validateCachedVideos();
          if (("https://s3.amazonaws.com/tapjoy/videos/assets/watermark.png" != null) && ("https://s3.amazonaws.com/tapjoy/videos/assets/watermark.png".length() > 0));
          try
          {
            URL localURL = new URL("https://s3.amazonaws.com/tapjoy/videos/assets/watermark.png");
            URLConnection localURLConnection = localURL.openConnection();
            localURLConnection.setConnectTimeout(15000);
            localURLConnection.setReadTimeout(25000);
            localURLConnection.connect();
            TapjoyVideo.access$202(BitmapFactory.decodeStream(localURL.openConnection().getInputStream()));
            TapjoyVideo.this.setVideoIDs();
            TapjoyVideo.access$402(TapjoyVideo.this, true);
            if (TapjoyVideo.this.cacheAuto)
            {
              TapjoyLog.i("TapjoyVideo", "trying to cache because of cache_auto flag...");
              TapjoyVideo.this.cacheVideos();
            }
            TapjoyLog.i("TapjoyVideo", "------------------------------");
            TapjoyLog.i("TapjoyVideo", "------------------------------");
            TapjoyLog.i("TapjoyVideo", "INIT DONE!");
            TapjoyLog.i("TapjoyVideo", "------------------------------");
            return;
          }
          catch (Exception localException)
          {
            while (true)
              TapjoyLog.e("TapjoyVideo", "e: " + localException.toString());
          }
        }
        TapjoyVideo.videoNotifierError(2);
      }
    }).start();
    TapjoyConnectCore.setVideoEnabled(true);
  }

  public void initVideoAd(TapjoyVideoNotifier paramTapjoyVideoNotifier)
  {
    initVideoAd(paramTapjoyVideoNotifier, false);
  }

  public void initVideoAd(TapjoyVideoNotifier paramTapjoyVideoNotifier, boolean paramBoolean)
  {
    tapjoyVideoNotifier = paramTapjoyVideoNotifier;
    if (paramTapjoyVideoNotifier == null)
    {
      Log.e("TapjoyVideo", "Error during initVideoAd -- TapjoyVideoNotifier is null");
      return;
    }
    cacheVideos();
  }

  public void setVideoCacheCount(int paramInt)
  {
    this.videoCacheLimit = paramInt;
  }

  public void setVideoNotifier(TapjoyVideoNotifier paramTapjoyVideoNotifier)
  {
    tapjoyVideoNotifier = paramTapjoyVideoNotifier;
  }

  public boolean startVideo(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6)
  {
    int i = 1;
    TapjoyLog.i("TapjoyVideo", "Starting video activity with video: " + paramString1);
    if ((paramString1 == null) || (paramString4 == null) || (paramString5 == null) || (paramString1.length() == 0) || (paramString4.length() == 0) || (paramString5.length() == 0))
    {
      TapjoyLog.i("TapjoyVideo", "aborting video playback... invalid or missing parameter");
      return false;
    }
    this.videoToPlay = ((TapjoyVideoObject)this.cachedVideos.get(paramString1));
    if (!"mounted".equals(Environment.getExternalStorageState()))
    {
      TapjoyLog.e("TapjoyVideo", "Cannot access external storage");
      videoNotifierError(1);
      return false;
    }
    if (this.videoToPlay == null)
    {
      TapjoyLog.i("TapjoyVideo", "video not cached... checking uncached videos");
      this.videoToPlay = ((TapjoyVideoObject)this.uncachedVideos.get(paramString1));
      if (this.videoToPlay == null)
      {
        if ((paramString6 != null) && (paramString6.length() > 0))
        {
          TapjoyVideoObject localTapjoyVideoObject = new TapjoyVideoObject();
          localTapjoyVideoObject.offerID = paramString1;
          localTapjoyVideoObject.currencyName = paramString2;
          localTapjoyVideoObject.currencyAmount = paramString3;
          localTapjoyVideoObject.clickURL = paramString4;
          localTapjoyVideoObject.webviewURL = paramString5;
          localTapjoyVideoObject.videoURL = paramString6;
          this.uncachedVideos.put(paramString1, localTapjoyVideoObject);
          this.videoToPlay = ((TapjoyVideoObject)this.uncachedVideos.get(paramString1));
        }
      }
      else
        i = 0;
    }
    else
    {
      this.videoToPlay.currencyName = paramString2;
      this.videoToPlay.currencyAmount = paramString3;
      this.videoToPlay.clickURL = paramString4;
      this.videoToPlay.webviewURL = paramString5;
      this.videoToPlay.videoURL = paramString6;
      TapjoyLog.i("TapjoyVideo", "videoToPlay: " + this.videoToPlay.offerID);
      TapjoyLog.i("TapjoyVideo", "amount: " + this.videoToPlay.currencyAmount);
      TapjoyLog.i("TapjoyVideo", "currency: " + this.videoToPlay.currencyName);
      TapjoyLog.i("TapjoyVideo", "clickURL: " + this.videoToPlay.clickURL);
      TapjoyLog.i("TapjoyVideo", "location: " + this.videoToPlay.dataLocation);
      TapjoyLog.i("TapjoyVideo", "webviewURL: " + this.videoToPlay.webviewURL);
      TapjoyLog.i("TapjoyVideo", "videoURL: " + this.videoToPlay.videoURL);
      if ((i == 0) || (this.videoToPlay.dataLocation == null))
        break label567;
      File localFile = new File(this.videoToPlay.dataLocation);
      if ((localFile != null) && (localFile.exists()))
        break label567;
      TapjoyLog.e("TapjoyVideo", "video file does not exist.");
      return false;
    }
    TapjoyLog.e("TapjoyVideo", "no video data and no video url - aborting playback...");
    return false;
    label567: Intent localIntent = new Intent(this.context, TapjoyVideoView.class);
    localIntent.setFlags(268435456);
    localIntent.putExtra("VIDEO_PATH", paramString1);
    this.context.startActivity(localIntent);
    return true;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.tapjoy.TapjoyVideo
 * JD-Core Version:    0.6.2
 */